//
//  PointsHistoryMigration.swift
//  hello
//
//  Created by 赵康 on 2025/5/28.
//

import Fluent
import Vapor

extension PointsHistory {
  struct Migration: AsyncMigration {
    var name: String { "PointsHistoryMigration" }
    
    func prepare(on database: any Database) async throws {
      try await database.schema(PointsHistory.schema)
        .id()
        .field(PointsHistory.FieldKeys.user, .uuid, .required, .references(User.schema, .id))
        .field(PointsHistory.FieldKeys.amount, .int, .required)
        .field(PointsHistory.FieldKeys.balance, .int, .required)
        .field(PointsHistory.FieldKeys.type, .int, .required)
        .field(PointsHistory.FieldKeys.description, .string, .required)
        .field(PointsHistory.FieldKeys.createdAt, .datetime, .required)
        .create()
    }
    
    func revert(on database: any Database) async throws {
      try await database.schema(PointsHistory.schema).delete()
    }
  }
} 